//表盘
#include<graphics.h>
#include<conio.h>
#include<math.h>

#define high 480
#define width 640
#define pi 3.14159

int main()
{
	initgraph(width,high);

	int center_x,center_y;//中心
	center_x=width/2;
	center_y=high/2;

	int secondlength;//秒针长度
	secondlength=width/4-20;
	int minutelength;//分针长度
	minutelength=width/5-25;
	int hourlength;//时针长度
	hourlength=width/6-30;
	int radius=190;//表盘半径

	int secondend_x,secondend_y;//秒针终点
	int minuteend_x,minuteend_y;//分针终点
	int hourend_x,hourend_y;//时针终点

	float secondangle=0;//秒针对应角度
	float minuteangle=0;//分针对应角度
	float hourangle=0;//时针对应角度

	SYSTEMTIME ti;//定义变量系统时间
	
	BeginBatchDraw();
	while(1)
	{
	GetLocalTime(&ti);
	secondangle=ti.wSecond*2*pi/60;
	minuteangle=ti.wMinute*2*pi/60;
	if(ti.wHour<=12)
		hourangle=ti.wHour*2*pi/12;
	else
		hourangle=(ti.wHour-12)*2*pi/12;

	secondend_x=center_x+secondlength*sin(secondangle);
	secondend_y=center_y-secondlength*cos(secondangle);
	minuteend_x=center_x+minutelength*sin(minuteangle);
	minuteend_y=center_y-minutelength*cos(minuteangle);
	hourend_x=center_x+hourlength*sin(hourangle);
	hourend_y=center_y-hourlength*cos(hourangle);




	//画秒针
	setlinestyle(PS_SOLID,2);
	setcolor(WHITE);
	line(center_x,center_y,secondend_x,secondend_y);
	//画分针
	setlinestyle(PS_SOLID,2);
	setcolor(BLUE);
	line(center_x,center_y,minuteend_x,minuteend_y);
	//画时针
	setlinestyle(PS_SOLID,2);
	setcolor(RED);
	line(center_x,center_y,hourend_x,hourend_y);
	FlushBatchDraw();

	//画表盘
	setlinecolor(YELLOW);
	circle(center_x,center_y,radius);
	//画刻度
	setlinecolor(GREEN);
	line(center_x+radius,center_y,center_x+radius-20,center_y);
	line(center_x-radius,center_y,center_x-radius+20,center_y);
	line(center_x,center_y+radius,center_x,center_y+radius-20);
	line(center_x,center_y-radius,center_x,center_y-radius+20);
	line(center_x+cos(pi/3)*radius,center_y-sin(pi/3)*radius,center_x+cos(pi/3)*(radius-10),center_y-sin(pi/3)*(radius-10));
	line(center_x+cos(pi/6)*radius,center_y-sin(pi/6)*radius,center_x+cos(pi/6)*(radius-10),center_y-sin(pi/6)*(radius-10));
	line(center_x-cos(pi/3)*radius,center_y-sin(pi/3)*radius,center_x-cos(pi/3)*(radius-10),center_y-sin(pi/3)*(radius-10));
	line(center_x-cos(pi/6)*radius,center_y-sin(pi/6)*radius,center_x-cos(pi/6)*(radius-10),center_y-sin(pi/6)*(radius-10));
	line(center_x-cos(pi/3)*radius,center_y+sin(pi/3)*radius,center_x-cos(pi/3)*(radius-10),center_y+sin(pi/3)*(radius-10));
	line(center_x-cos(pi/6)*radius,center_y+sin(pi/6)*radius,center_x-cos(pi/6)*(radius-10),center_y+sin(pi/6)*(radius-10));
	line(center_x+cos(pi/3)*radius,center_y+sin(pi/3)*radius,center_x+cos(pi/3)*(radius-10),center_y+sin(pi/3)*(radius-10));
	line(center_x+cos(pi/6)*radius,center_y+sin(pi/6)*radius,center_x+cos(pi/6)*(radius-10),center_y+sin(pi/6)*(radius-10));
	//我的时钟
	outtextxy(center_x-30,center_y-radius-20,"我的时钟");
	outtextxy(center_x-8,center_y-radius+22,"12");
	outtextxy(center_x-4,center_y+radius-36,"6");
	outtextxy(center_x-radius+22,center_y-6,"9");
	outtextxy(center_x+radius-30,center_y-6,"3");
	outtextxy(center_x+cos(pi/3)*(radius-10)-5,center_y-sin(pi/3)*(radius-10),"1");
	outtextxy(center_x+cos(pi/6)*(radius-10)-7,center_y-sin(pi/6)*(radius-10)-4,"2");
	outtextxy(center_x-cos(pi/3)*(radius-10)-3,center_y-sin(pi/3)*(radius-10)+3,"11");
	outtextxy(center_x-cos(pi/6)*(radius-10),center_y-sin(pi/6)*(radius-10),"10");
	outtextxy(center_x-cos(pi/3)*(radius-10)+2,center_y+sin(pi/3)*(radius-10)-10,"7");
	outtextxy(center_x-cos(pi/6)*(radius-10)+2,center_y+sin(pi/6)*(radius-10)-6,"8");
	outtextxy(center_x+cos(pi/3)*(radius-10)-9,center_y+sin(pi/3)*(radius-10)-12,"5");
	outtextxy(center_x+cos(pi/6)*(radius-10)-9,center_y+sin(pi/6)*(radius-10)-10,"4");


	Sleep(50);
	//隐藏前一帧
	setcolor(BLACK);
	line(center_x,center_y,secondend_x,secondend_y);
	setcolor(BLACK);
	line(center_x,center_y,minuteend_x,minuteend_y);
	setcolor(BLACK);
	line(center_x,center_y,hourend_x,hourend_y);

	}
	EndBatchDraw();

	getch();
	closegraph();

	return 0;
}